
using System;
using System.Text;
using SpotifyGenNHibernate.CEN;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Criterion;
using NHibernate.Exceptions;
using SpotifyGenNHibernate.EN.Spotify;

namespace SpotifyGenNHibernate.CAD.Spotify
{
        public partial class ListaDeReproduccionCAD : BasicCAD, IListaDeReproduccionCAD
        {
        public ListaDeReproduccionCAD() : base ()
        {
        }

        public ListaDeReproduccionCAD(ISession sessionAux) : base (sessionAux)
        {
        }



        public ListaDeReproduccionEN ReadOIDDefault (int id)
        {
                ListaDeReproduccionEN listaDeReproduccionEN = null;

                try
                {
                        SesssionInitializeTransaction ();
                        listaDeReproduccionEN = (ListaDeReproduccionEN)session.Load (typeof(ListaDeReproduccionEN),
                                id

                                );
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in ListaDeReproduccionCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }

                return listaDeReproduccionEN;
        }


        public int New_ (ListaDeReproduccionEN listaDeReproduccion)
        {
                try
                {
                        SesssionInitializeTransaction ();

                        session.Save (listaDeReproduccion);
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in ListaDeReproduccionCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }

                return listaDeReproduccion.Id;
        }

        public void Destroy (int id)
        {
                try
                {
                        SesssionInitializeTransaction ();
                        ListaDeReproduccionEN listaDeReproduccionEN = (ListaDeReproduccionEN)session.Load (typeof(ListaDeReproduccionEN),
                                id

                                );
                        session.Delete (listaDeReproduccionEN);
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in ListaDeReproduccionCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }
        }

        public void Editar (ListaDeReproduccionEN listaDeReproduccion)
        {
                try
                {
                        SesssionInitializeTransaction ();
                        ListaDeReproduccionEN listaDeReproduccionEN = (ListaDeReproduccionEN)session.Load (typeof(ListaDeReproduccionEN), listaDeReproduccion.Id);

                        listaDeReproduccionEN.Nombre = listaDeReproduccion.Nombre;

                        session.Update (listaDeReproduccionEN);
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in ListaDeReproduccionCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }
        }
        }
}
